#  Gmof - A meta-object facility library based on OMG's EMOF 
#
#  Copyright (C) 2007 Peter Hagg <peter.hagg@iki.fi>
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
from Type import Type
from NullPointerException import NullPointerException
from IllegalArgumentException import IllegalArgumentException

class Class(Type):
    def __init__(self, name):
        super(Class, self).__init__(name)
        
        self.isAbstract = False
        
        self.ownedAttribute = []
        self.superClass = []
        self.ownedOperation = []
        
    # From GMOF.Element
    # NOTE: Supports only properties with an upper bound of 1
    def get(self, property):
        found = False
        for attribute in self.ownedAttribute:
            if (attribute.name == property.name):
                found = True
                
        if (found == False):
            raise IllegalArgumentException("property is not a member of class")
        
        for attribute in self.ownedAttribute:
            if (property.name == attribute.name):
                return attribute.type.value
        
        return None

    def set(self, property, object):
        found = False
        for attribute in self.metaClass.ownedAttribute:
            if (attribute.name == property.name):
                found = True
                
        if (found == False):
            raise IllegalArgumentException("property is not a member of self.metaClass")
        
        for attribute in self.ownedAttribute:
            if (attribute.name == property.name):
                attribute.type.value = object
                
    def isSet(self, property):
        found = False
        for attribute in self.ownedAttribute:
            if (attribute.name == property.name):
                found = True
                
        if (found == False):
            raise IllegalArgumentException("property is not a member of self.klass")
        
        for attribute in self.ownedAttribute:
            if (attribute.name == property.name):
                if (attribute.type.value != attribute.default):
                    return True
                else:
                    return False
        
        return False
    
    def unset(self, property):
        found = False
        for attribute in self.metaClass.ownedAttribute:
            if (attribute.name == property.name):
                found = True
                
        if (found == False):
            raise IllegalArgumentException("property is not a member of self.metaClass")

        for attribute in self.ownedAttribute:
            if (attribute.name == property.name):
                attribute.type.value = attribute.default
        
